package com.client.ryt.basic;

import android.app.AlertDialog;
import android.app.NotificationManager;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.MenuItem;
import android.widget.Toast;

import com.client.ryt.R;
import com.client.ryt.widget.progressdialog.CustomProgressDialog;


/**
 * Created by Administrator on 2014/8/31.
 */
public class BaseActivity extends ActionBarActivity implements BaseActivity_I  {
    protected SharedPreferences preferences;
    protected NotificationManager notificationManager;
    protected Context context = null;
    protected CustomProgressDialog progressDialog = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        String className = ((Object)this).getClass().getSimpleName();
        if(className.equals("MainActivity") || className.equals("LoginActivity")){
            android.support.v7.app.ActionBar actionBar = getSupportActionBar();
            actionBar.setDisplayUseLogoEnabled(true);
            actionBar.setHomeButtonEnabled(true);
            actionBar.setDisplayShowHomeEnabled(true);
            actionBar.setLogo(R.drawable.ic_launcher);
            actionBar.setDisplayHomeAsUpEnabled(false);
        }else{
            android.support.v7.app.ActionBar actionBar = getSupportActionBar();
            actionBar.setDisplayUseLogoEnabled(true);
            actionBar.setHomeButtonEnabled(true);
            actionBar.setDisplayShowHomeEnabled(true);
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setLogo(R.drawable.ic_launcher);
            actionBar.setHomeAsUpIndicator(R.drawable.abc_ic_ab_back_holo_dark);
        }

        context = this;
        notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        progressDialog = CustomProgressDialog.createDialog(this);
        BaseApplication.getInstance().addActivity(this);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch(item.getItemId()) {
            case android.R.id.home:
                finish();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public BaseApplication getBaseApplication() {
        return BaseApplication.getInstance();
    }

    @Override
    public void stopService() {

    }

    @Override
    public void startService() {

    }

    @Override
    public boolean hasInternetConnected() {
        return false;
    }

    @Override
    public void isExit() {
        new AlertDialog.Builder(context).setTitle("确定退出吗?")
                .setNeutralButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        stopService();
                        BaseApplication.getInstance().exit();
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                }).show();
    }

    @Override
    public boolean hasLocationGPS() {
        return false;
    }

    @Override
    public boolean hasLocationNetWork() {
        return false;
    }

    @Override
    public void checkMemoryCard() {

    }

    @Override
    public void showToast(String text, int longint) {
        Toast.makeText(context, text, longint).show();
    }

    @Override
    public void showToast(String text) {
        Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
    }

    @Override
    public ProgressDialog getProgressDialog() {
        return null;
    }

    @Override
    public Context getContext() {
        return null;
    }

    @Override
    public SharedPreferences getLoginUserSharedPre() {
        return null;
    }

    @Override
    public void setNotiType(int iconId, String contentTitle, String contentText, Class activity, String from) { }

    public void startProgressDialog(){
        if (progressDialog == null){
            progressDialog = CustomProgressDialog.createDialog(this);
            progressDialog.setMessage("正在加载中...");
        }

        progressDialog.show();
    }

    public void stopProgressDialog(){
        if (progressDialog != null){
            progressDialog.dismiss();
            progressDialog = null;
        }
    }
}
